




/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：03/02/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.application.yfwaring.struts.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.application.yfwaring.commons.Constants;
import com.application.yfwaring.entity.YfWarning;
import com.application.yfwaring.service.YfWarningService;
import com.application.yfwaring.struts.form.YfWarningForm;
import com.manager.commons.CommonUtil;
import com.manager.commons.RandomKey;
import com.manager.commons.page.PageBean;
 /**
 * 
 * Description:YfWarningAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060    <br />
 * 
 * History: <br />
 * 
 * 03/02/2012 
 * 
 */
public class YfWarningAction extends DispatchAction
{
       
       /**
	 * Service层实例
	 */
	private YfWarningService yfWarningService;

	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
        private YfWarning yfWarning;


        /**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getYfWarningPartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchYfWarning" + "开始");
		YfWarningForm yfWarning = (YfWarningForm)form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List yfWarningList = null;
		resultSize = yfWarningService.getAllCountYfWarning(yfWarning);
		pageBean = PageBean.getPageBean("yfWarningTab", resultSize,request);
		yfWarningList = yfWarningService.searchYfWarning(yfWarning,pageBean);
		request.setAttribute("yfWarningList", yfWarningList);

		log.debug("searchYfWarning" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

        /**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddYfWarning(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toAddYfWarnings");
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addYfWarning(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addYfWarnings");
		YfWarning yfWarning = this.getYfWarning(form);
                yfWarning.setId(RandomKey.generateID_Long_19());
		 yfWarning.setOperateid(CommonUtil.getCurrentUser(request).getId());
		 yfWarning.setCreateDate(new Date());

		this.yfWarningService.insertObject(yfWarning);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteYfWarning(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("deleteYfWarnings");
		YfWarningForm yfWarningForm = (YfWarningForm) form;
		this.yfWarningService.deleteYfWarnings(yfWarningForm);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateYfWarning(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toUpdateYfWarnings");

		YfWarning yfWarning = this.getYfWarning(form);
		yfWarning = this.yfWarningService.getYfWarning(yfWarning);
		request.setAttribute(Constants.YFWARNING, yfWarning);
		return mapping.findForward(Constants.SUCCESS);
	}

        
	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateYfWarning(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("updateYfWarnings");
		YfWarning yfWarning = this.getYfWarning(form);
	        yfWarning.setOperateid(CommonUtil.getCurrentUser(request).getId());
		 yfWarning.setCreateDate(new Date());
		this.yfWarningService.updateObject(yfWarning);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewYfWarning(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("viewYfWarning");

		YfWarning yfWarning = this.getYfWarning(form);
		yfWarning = this.yfWarningService.getYfWarning(yfWarning);
		request.setAttribute(Constants.YFWARNING, yfWarning);
		return mapping.findForward(Constants.SUCCESS);
	}

	// get--set
	/**
	 * @return the YfWarningService
	 */
	public YfWarningService getYfWarningService() {
		return this.yfWarningService;
	}

	/**
	 * @param YfWarningService
	 *  the YfWarningService to set
	 */
	public void setYfWarningService(YfWarningService yfWarningService) {
		this.yfWarningService = yfWarningService;
	}

	/**
	 * 获取YfWarning实体
	 * @param ActionForm
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @return the YfWarning
	 */
	public YfWarning getYfWarning(ActionForm form) throws IllegalAccessException, InvocationTargetException {
		YfWarningForm yfWarningForm = (YfWarningForm) form;
		yfWarning = new YfWarning();
		BeanUtils.copyProperties(yfWarning, yfWarningForm);
		return yfWarning;
	}
    
        public void setYfWarning(YfWarning yfWarning) {
		this.yfWarning = yfWarning;
	}

}
